package models

import (
	"time"
)

type Answer struct {
	ID           uint      `gorm:"primarykey" json:"id"`
	Content      string    `gorm:"type:text;not null" json:"content"`
	AnswererID   uint      `json:"answererId"`
	QuestionID   uint      `json:"questionId"`
	VoteCount    int       `gorm:"default:0" json:"voteCount"`
	CommentCount int       `gorm:"default:0" json:"commentCount"`
	CreatedAt    time.Time `json:"createdAt"`
	UpdatedAt    time.Time `json:"updatedAt"`

	// 关联
	Answerer   User       `gorm:"foreignKey:AnswererID" json:"answerer,omitempty"`
	Question   Question   `gorm:"foreignKey:QuestionID" json:"question,omitempty"`
	Likes      []*User    `gorm:"many2many:user_liking_answers" json:"likes,omitempty"`
	Collectors []*User    `gorm:"many2many:user_collecting_answers" json:"collectors,omitempty"`
	Comments   []*Comment `gorm:"polymorphic:Resource" json:"comments,omitempty"`
}
